﻿using System.Collections.Generic;
using System.Data;
using MaLu.Data;
using System;

namespace MaLu.BusiLogic
{
    public class BLThree
    {
        public static int SaveEvent(IDbProvider provider, Guid id, Guid DeptID, string DeptDspName, string ReportTime,
            string MainContent, int Status, string Signature, string Sug, string SugTime, string SugorName, DateTime SugCreateTime,
            string CreatorName, string InstanceContent, string AttachIDs)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@ID", DataType.GUID, id));
            paraList.Add(SqlHelper.Instance.CreateParameter("@DeptID", DataType.GUID, DeptID));
            paraList.Add(SqlHelper.Instance.CreateParameter("@DeptDspName", DataType.VarChar, 50, DeptDspName));
            paraList.Add(SqlHelper.Instance.CreateParameter("@ReportTime", DataType.VarChar, 50, ReportTime));
            paraList.Add(SqlHelper.Instance.CreateParameter("@MainContent", DataType.Text, 50, MainContent));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Status", DataType.Int32, 8, Status));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Signature", DataType.VarChar, 50, Signature));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Sug", DataType.VarChar, 1000, Sug));
            paraList.Add(SqlHelper.Instance.CreateParameter("@SugTime", DataType.VarChar, 50, SugTime));
            paraList.Add(SqlHelper.Instance.CreateParameter("@SugorName", DataType.VarChar, 50, SugorName));
            paraList.Add(SqlHelper.Instance.CreateParameter("@SugCreateTime", DataType.DateTime, SugCreateTime));
            paraList.Add(SqlHelper.Instance.CreateParameter("@CreatorName", DataType.VarChar, 50, CreatorName));
            paraList.Add(SqlHelper.Instance.CreateParameter("@InstanceContent", DataType.VarChar, 2000, InstanceContent));
            paraList.Add(SqlHelper.Instance.CreateParameter("@AttachIDs", DataType.VarChar, 400, AttachIDs));
            DataTable ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_TSaveEvent", paraList.ToArray()).Tables[0];
            int result = 0;
            int.TryParse(ds.Rows[0][0].ToString(), out result);
            return result;
        }

        public static int SaveEvent2(IDbProvider provider, Guid id, Guid DeptID, string DeptDspName,
            int Status, string Signature, string year, string month, string day, string SigerName, DateTime SugCreateTime,
            string CreatorName)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@ID", DataType.GUID, id));
            paraList.Add(SqlHelper.Instance.CreateParameter("@DeptID", DataType.GUID, DeptID));
            paraList.Add(SqlHelper.Instance.CreateParameter("@DeptDspName", DataType.VarChar, 50, DeptDspName));           
            paraList.Add(SqlHelper.Instance.CreateParameter("@Status", DataType.Int32, 8, Status));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Year", DataType.VarChar, 6, year));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Month", DataType.VarChar, 6, month));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Day", DataType.VarChar, 10, day));
            paraList.Add(SqlHelper.Instance.CreateParameter("@Signature", DataType.VarChar, 50, Signature));
            paraList.Add(SqlHelper.Instance.CreateParameter("@SigerName", DataType.VarChar, 50, SigerName));           
            paraList.Add(SqlHelper.Instance.CreateParameter("@SigeCreateTime", DataType.DateTime, SugCreateTime));
            paraList.Add(SqlHelper.Instance.CreateParameter("@CreatorName", DataType.VarChar, 50, CreatorName));           
            DataTable ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_TSaveEvent2", paraList.ToArray()).Tables[0];
            int result = 0;
            int.TryParse(ds.Rows[0][0].ToString(), out result);
            return result;
        }
        public static DataSet GetEvent(IDbProvider provider, Guid id)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@ID", DataType.GUID, id));

            DataSet ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_GetEventDetail", paraList.ToArray());
            return ds;
        }
        public static DataSet GetEvent2(IDbProvider provider, Guid id)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@ID", DataType.GUID, id));

            DataSet ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_GetEventDetail2", paraList.ToArray());
            return ds;
        }
        public static int DeleteEvent(IDbProvider provider, Guid id)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@EventID", DataType.GUID, id));

            DataSet ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_DeleteEvent", paraList.ToArray());
            int result = 0;
            int.TryParse(ds.Tables[0].Rows[0][0].ToString(), out result);
            return result;
        }

        public static int DeleteEvent2(IDbProvider provider, Guid id)
        {
            List<IDataParameter> paraList = new List<IDataParameter>();
            paraList.Add(SqlHelper.Instance.CreateParameter("@EventID", DataType.GUID, id));

            DataSet ds = SqlHelper.Instance.ExecuteProcedure(provider, "Proc_DeleteEvent2", paraList.ToArray());
            int result = 0;
            int.TryParse(ds.Tables[0].Rows[0][0].ToString(), out result);
            return result;
        }
    }
}
